package zhizelian;

// 测试类
public class PurchaseApprovalSystemTest {
    public static void main(String[] args) {
        // 构建审批链
        Approver chain = ApprovalChainBuilder.buildChain();
        Meeting meeting = new Meeting();
        
        // 创建采购请求
        PurchaseRequest request1 = new PurchaseRequest("PR2023001", 8000, "购买办公用品");
        PurchaseRequest request2 = new PurchaseRequest("PR2023002", 30000, "购买电脑设备");
        PurchaseRequest request3 = new PurchaseRequest("PR2023003", 150000, "购买生产设备");
        PurchaseRequest request4 = new PurchaseRequest("PR2023004", 250000, "购买新生产线");
        
        // 处理采购请求
        System.out.println("=== 处理采购请求1 ===");
        chain.processRequest(request1);
        
        System.out.println("\n=== 处理采购请求2 ===");
        chain.processRequest(request2);
        
        System.out.println("\n=== 处理采购请求3 ===");
        chain.processRequest(request3);
        
        System.out.println("\n=== 处理采购请求4 ===");
        Approver lastApprover = findLastApprover(chain);
        if (!lastApprover.approveRequest(request4)) {
            meeting.processRequest(request4);
        }
    }
    
    private static Approver findLastApprover(Approver approver) {
        Approver current = approver;
        while (current.getSuccessor() != null) {
            current = current.getSuccessor();
        }
        return current;
    }
}